<template>
  <div v-if="orderDetail.orderBase" class="orderDetail">
    <div class="content margin_30">
      <div class="steps">
        <el-steps :active="status" align-center>
          <el-step title="待付款" description="" />
          <el-step title="待发货" description="" />
          <el-step title="已发货" description="" />
          <el-step title="已完成" description="" />
          <el-step title="退货" description="" />
        </el-steps>
      </div>
      <div class="orderMes margin_20 steps">
        <el-row>
          <el-col :span="6" :offset="0">
            <div class="marginBottom_20 ">订单信息:
              <el-button v-if="status==1" type="danger" size="small">待付款</el-button>
              <el-button v-if="status==2" type="warning" size="mini">待发货</el-button>
              <el-button v-if="status==3" type="primary" size="mini">已发货</el-button>
              <el-button v-if="status==4" type="primary" plain size="mini">已完成</el-button>
              <el-button v-if="status==5" type="info" plain size="mini">退货</el-button>
              <el-button v-if="status==6" type="info" size="mini">无效订单</el-button>
            </div>

          </el-col>
        </el-row>
        <el-row class="height_40">
          <el-col :span="6" :offset="0">
            <div><span>订单金额:</span>{{ orderDetail.orderBase.totalAmount }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>订单编号:</span>{{ orderDetail.orderBase.orderSn }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>用户账号:</span>{{ orderDetail.orderBase.memberUsername }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>备注:</span>{{ orderDetail.orderBase.note }}</div>
          </el-col>
        </el-row>
        <el-row class="height_40">
          <el-col :span="6" :offset="0">
            <div><span>下单时间:</span>{{ orderDetail.orderBase.createTime }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>付款时间:</span>{{ orderDetail.orderBase.paymentTime }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>发货时间:</span>{{ orderDetail.orderBase.deliveryTime }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>收货时间:</span>{{ orderDetail.orderBase.receiveTime }}</div>
          </el-col>
        </el-row>

      </div>
      <div class="userMes margin_20 steps">
        <el-row>
          <el-col :span="6" :offset="0">
            <div class="marginBottom_20">收货人信息:</div>
          </el-col>
        </el-row>
        <el-row class="height_40">
          <el-col :span="6" :offset="0">
            <div><span>收货人:</span>{{ orderDetail.orderBase.receiverName }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>用户姓名:</span>{{ orderDetail.orderBase.memberUsername }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>手机号码:</span>{{ orderDetail.orderBase.receiverPhone }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>邮政编码:</span>{{ orderDetail.orderBase.receiverPostCode }}</div>
          </el-col>
        </el-row>

        <el-row class="height_40">
          <el-col :span="6" :offset="0">
            <div><span>地市:</span>{{ orderDetail.orderBase.receiverProvince + orderDetail.orderBase.receiverCity }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>详细地址:</span>{{ orderDetail.orderBase.receiverDetailAddress }}</div>
          </el-col>
        </el-row>

      </div>
      <div class="goodsMes margin_20">
        <div class="marginBottom_20">商品信息:</div>
        <el-table :data="orderDetail.orderItems" border stripe>
          <el-table-column
            prop="productName"
            label="商品名称"
            width="200"
            align="center"
          />
          <el-table-column
            prop=" "
            label="商品图片"
            width="200"
            align="center"
          >
            <template v-slot="scope">
              <img style="width:100px;height:100px" :src="scope.row.productPic" alt="">
            </template>
          </el-table-column>
          <el-table-column
            prop="isReturn"
            label="是否退货"
            align="center"
          />
          <el-table-column
            prop="productBrand"
            label="品牌"
            align="center"
          />
          <el-table-column
            prop="productPrice"
            label="价格"
            align="center"
          />
          <el-table-column
            prop="productQuantity"
            label="商品数量"
            align="center"
          />
          <el-table-column
            prop="totalPrice"
            label="小计"
            fixed="right"
            align="center"
          />
        </el-table>
      </div>
      <div class="userMes margin_20">
        <div class="marginBottom_20">费用信息:</div>
        <el-row class="height_40">
          <el-col :span="6" :offset="0">
            <div><span>运费金额:</span>{{ orderDetail.orderBase.freightAmount }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>订单总金额:</span>{{ orderDetail.orderBase.totalAmount }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>实际金额:</span>{{ orderDetail.orderBase.payAmount }}</div>
          </el-col>
          <el-col :span="6" :offset="0">
            <div><span>促销优化金额:</span>{{ orderDetail.orderBase.promotionAmount }}</div>
          </el-col>
        </el-row>

      </div>
      <div v-if="status == 2">
        <el-form ref="form" :model="form" :inline="true" size="small">
          <el-form-item label="物流公司">
            <el-select v-model="form.deliveryCompany" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="物流单号">
            <el-input v-model="form.deliverySn" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="sendGoods">确认发货</el-button>
          </el-form-item>
        </el-form>

      </div>
      <div v-if="status == 3 || status == 4" class="goodsMes margin_20">
        <div class="marginBottom_20">物流信息:{{ orderDetail.orderBase.deliveryCompany }}[{{ orderDetail.orderBase.deliverySn }}]</div>
        <el-table :data="deliveryMes" border stripe>
          <el-table-column
            prop="time"
            label="时间"
            width="200"
            align="center"
          />
          <el-table-column
            prop="status"
            label="状态"
            width="200"
            align="center"
          />
          <el-table-column
            prop="note"
            label="备注"
            align="center"
          />
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { orderDetail, sendDone } from '@/api/orderManage/orderDetail/index'
export default {
  name: 'VueAdminTemplateMasterIndex',

  data() {
    return {
      status: 0,
      orderDetail: [],
      options: ['顺丰快递', '韵达快递', '中国邮政', '申通快递', '中通快递'],
      deliveryMes: [{
        time: '2015-03-06 21:16:58',
        status: '深圳市横岗速递营销部已收件',
        note: '揽投员姓名：钟定基;联系电话：13883838888'
      }, {
        time: '2015-03-07 14:25:00',
        status: '离开深圳市 发往广州市',
        note: ''
      }, {
        time: '2015-03-08 00:17:00',
        status: '到达广东速递物流公司广航中心处理中心（经转）',
        note: ''
      }, {
        time: '2015-03-09 09:01:00',
        status: '离开广州市 发往北京市（经转）',
        note: ''
      }, {
        time: '2015-03-09 18:39:00',
        status: '离开北京市 发往呼和浩特市（经转）',
        note: ''
      }, {
        time: '2015-03-10 18:06:00',
        status: '到达 呼和浩特市 处理中心',
        note: ''
      }, {
        time: '2015-03-11 09:53:48',
        status: '呼和浩特市邮政速递物流分公司金川揽投部安排投递',
        note: '投递员姓名：安长虹;联系电话：18047140142'
      }],
      form: {
        orderId: this.$route.query.id,
        deliverySn: '',
        deliveryCompany: ''
      }
    }
  },

  created() {
    orderDetail(this.$route.query.id).then(res => {
      console.log(res)
      res.data.orderDetail.orderItems.forEach(ele => {
        ele.isReturn = ele.isReturn ? '是' : '否'
      })
      this.status = res.data.orderDetail.orderBase.status + 1
      this.orderDetail = res.data.orderDetail
    })
  },

  mounted() {

  },

  methods: {
    sendGoods() {
      sendDone(this.form).then(res => {
        this.$route.push('/orderManage/orderList')
      })
    }
  }
}
</script>

<style scoped lang="scss">
.orderDetail{
  overflow: hidden;
  background-color: #f0f2f5;
  font-size: 14px;
  .margin_20{
    margin: 20px 0;
  }
  .marginBottom_20{
    margin-bottom: 20px;
  }
  .height_40{
    height: 40px;
    line-height: 40px;
  }
  span{
    margin-right: 10px;
  }
  .content{
    background-color: #fff;
    padding: 20px;

    .steps{
      border-bottom: 2px solid #dcdfe6;
      padding-bottom: 30px;
    }
  }
}
</style>
